<?php
	// set timeout period in seconds
	$inactive = SESSION_EXPIRE_TIME;

	// check to see if $_SESSION['timeout'] is set
	if(isset($_SESSION['timeout']))
	{
		$session_life = time() - $_SESSION['timeout'];
		if($session_life > $inactive)
		{
			addLogByUsername("Session Expired");
			session_unset();
			session_destroy();
			session_write_close();
			setcookie(session_name(),'',0,'/');
			session_regenerate_id(true);
			
			session_start();
			$_SESSION['url_referer'] = getURL();
			
			//echo $_SESSION['url_referer'];die();
			session_regenerate_id(true);
			
			
			
			setSessionMsg("exp");
			echo '<meta http-equiv="refresh" content="0;URL='.URL_HOME_SITE_ADMIN.'/login.php" >';	// expired (exp) = default session is expired, login / relogin needed
			die;
			
			//header("Location: ".URL_HOME_SITE_ADMIN."/login.php");
			
			//echo'<meta http-equiv="refresh" content="0;URL='.URL_HOME_SITE_ADMIN.'/login.php?msg=exp" >';	// expired (exp) = default session is expired, login / relogin needed
			//exit();
			//die;
		}
	}
	$_SESSION['timeout'] = time();

	// session variable needed
	if(empty($_SESSION['login']) || empty($_SESSION['userid']) || empty($_SESSION['username']) || empty($_SESSION['usergroupid']))
	{
		/*
		session_unset();
		session_destroy();
		session_write_close();
		setcookie(session_name(),'',0,'/');
		session_regenerate_id(true);
		*/
		setSessionMsg("li");
		echo '<meta http-equiv="refresh" content="0;URL='.URL_HOME_SITE_ADMIN.'/login.php" >';	// login (li) = default session is not found, login / relogin needed
		die;
	}
?>